/*
 * @Author: your name
 * @Date: 2020-10-15 08:34:36
 * @LastEditTime: 2021-12-20 13:55:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \sende_nuxt\nuxt.config.js
 */
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
  // Target (https://go.nuxtjs.dev/config-target)
  globalName: 'ssr',
  // target: 'static',
  mode: 'universal',
  // Global page headers (https://go.nuxtjs.dev/config-head)
  head: {
    title: '八仔电子商务公司|外贸进出口|网站建设|电商',
    meta: [
      { charset: 'utf-8' },
      { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { name: 'description', content: '外贸眼镜，老花镜，太阳镜' },
      { name: 'renderer', content: `sende` },
      // { hid: 'viewport', name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no' },
      { name: 'keywords', content: `八仔电子商务公司|外贸进出口|网站建设|电商` },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
      { rel: 'stylesheet', href: 'https://at.alicdn.com/t/font_2134070_3alqrlate6l.css' }
    ]
  },
  script: [
    // { src: '~/assets/tracking-min.js' },
    // { src: '~/assets/js/face-min.js' }
  ],
  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: [
    '~/assets/css/reset.css',
    '~/assets/scss/common.scss',
    '~/assets/scss/logic.scss',
    // 'element-ui/lib/theme-chalk/index.css',
  ],

  // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
    // { src: '~plugins/injectPlugins.js' },
    { src: '~/plugins/i18n.js' },
    { src: '~/plugins/vue-swiper.js', ssr: false },
    { src: '~/plugins/elementUI.js', ssr: true },
    { src: '~plugins/vueLazyLoad', ssr: false },
    { src: '~/plugins/tracking.js', ssr: false }
  ],
  // Auto import components (https://go.nuxtjs.dev/config-components)
  components: true,

  // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  buildModules: [
  ],

  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    "@nuxtjs/proxy",
    ['cookie-universal-nuxt', { parseJSON: false }]
  ],
  server: {
    port: process.env.NODE_ENV === 'development' ? 10012 : 10012, // default: 3000
    host: '0.0.0.0' // default: localhost,
  },
  // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  axios: {
    // 是否允许跨域
    proxy: true,
    // baseURL: "",
    // withCredentials: true,
  },
  router: {              // customize nuxt.js router (vue-router).
    middleware: ['i18n', 'permission'],   // middleware all pages of the application
    scrollBehavior(to, from, savedPosition) {
      return { x: 0, y: 0 }
    }
  },
  proxy: {
    // '/api/': { target: 'https://yj2.clucl.com/rest/V1', pathRewrite: {'^/api/': ''} }
  },
  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    vendor: ['axios', 'element-ui'], // 为防止重复打包
    productionSourceMap: false,
    plugins: [
      new CompressionPlugin({
        test: /\.js$|\.html$|\.css$|\.jpg$|\.png$|\.svg$|\.woff$|\.ttf$|\.woff2$/, // 匹配文件名
        threshold: 10240, // 对超过10kb的数据进行压缩
        deleteOriginalAssets: false, // 是否删除原文件
        algorithm: 'gzip',
        minRatio: 0.8 // 压缩率
      })
    ],
    extractCSS: true,
    optimization: { // 分割数据
      splitChunks: {
        minSize: 10000,
        maxSize: 250000,
        cacheGroups: { // 将局部样式全部提取成单独css文件；
          styles: {
            name: 'styles',
            test: /\.(css|vue)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    },
    babel: {
      plugins: [
        [ "component", {"libraryName": "element-ui",  "styleLibraryName": "theme-chalk"}] 
      ] 
    },
    analyze: {
      analyzerMode: 'static'
    }
  },
  // render: {
  //   bundleRenderer: {
  //     cache: require('lru-cache')({
  //       max: 1000,
  //       maxAge: 1000 * 60 * 15
  //     })
  //   }
  // }
}
